{% extends "../master.html" %}

{% block hfm_css %}
<style type="text/css">
    .layui-form-label{
        padding: 9px 8px;
    }
</style>
{% end %}

{% block page_content %}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <!--
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                    <span class="x-red">*</span>旧密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="oldpass" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
            </div>
            -->
            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    <span class="x-red">*</span>新密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="newpass" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div></div>
            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label">
                    <span class="x-red">*</span>确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" id="L_repass" name="repass" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                    <div class="layui-form-mid layui-word-aux">6到16个字符</div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs6" >
                    <button type="reset" class="layui-btn">重置</button>
                </div>
                <div class="layui-col-xs6" align='right'>
                    <button type="submit" class="layui-btn" lay-submit lay-filter="form_post" >确认</button>
                </div>
             </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
        layer = layui.layer;

        //监听提交
        form.on('submit(form_post)',
        function(data) {
            //console.log(data);
            //发异步，把数据提交给Tornado
            var passd = data.field;
            $.ajax({
                url: '/user/changepwd',
                type: 'post',
                data: passd,
                beforeSend: function () {
                    this.layerChandPwd = layer.load(0, {shade: [0.5, '#393D49']});
                },
                success: function (data) {
                    if (data.status == 'error') {
                        layer.msg(data.msg, {icon: 5});
                    } else if (data.status == 'success') {
                        layer.msg(data.msg, {
                            icon: 6,
                            time: 2000
                        }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        })
                    }
                },
                complete: function () {
                    layer.close(this.layerChandPwd)
                }
            });
            return false;
        });

    });
</script>
{% end %}
